package cn.kgc.springboot06.service;

import cn.kgc.springboot06.entity.Product;
import cn.kgc.springboot06.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: mosin
 * @version: v1.0  2022/5/24
 */
@Service
public class ProductServiceImpl  implements ProductService{

    @Autowired
    private ProductMapper productMapper;
    @Override
    public Map<String, Object> getAll() {
        HashMap<String, Object> map = new HashMap<>();
        ArrayList<String> productNames = new ArrayList<>();
        ArrayList<Integer> productNumbers = new ArrayList<>();
        List<Product> ps = productMapper.getAll();
        ps.forEach(p->{
            productNames.add(p.getProductName());
            productNumbers.add(p.getNumber());
        });

        map.put("names",productNames);
        map.put("numbers", productNumbers);
        return map;
    }
}
